package com.ziytek.web.citizen.config;

import com.ziytek.web.citizen.constant.NumConstant;
import lombok.RequiredArgsConstructor;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * @author fenghx
 */
@Component
@RefreshScope
@RequiredArgsConstructor
public class ConfigInit {

    private final SpringConfig springConfig;

    public Config getConfig() {
        List<Config> configs = springConfig.getConfigs();
        return CollectionUtils.isEmpty(configs) ? null : configs.getFirst();
    }

    public long getScheduledTimeDelay() {
        Config config = getConfig();
        return config != null && config.getScheduledTimeDelay() != null
                ? config.getScheduledTimeDelay() : NumConstant.LONG_ZERO;
    }

    public boolean isPrint() {
        Config config = getConfig();
        return config != null && config.isBasicDataPrinting();
    }

    public boolean isTest() {
        Config config = getConfig();
        return config != null && config.isTest();
    }

    public boolean isInterruptAutomatic() {
        Config config = getConfig();
        return config != null && config.isInterruptAutomatic();
    }


    public boolean isDbCharge() {
        Config config = getConfig();
        return config != null && config.isDbCharge();
    }

    public boolean isPro() {
        Config config = getConfig();
        return config != null && "pro".equalsIgnoreCase(config.getConfigProfiles());
    }

    public Float getMinCapStatsQuery() {
        Config config = getConfig();
        return config != null && config.getCapStatsQueryMin() != null
                ? config.getCapStatsQueryMin() : NumConstant.FLOAT_ZER;
    }

    public Integer getChargingCurrentLimitMax() {
        Config config = getConfig();
        return config != null && config.getChargeCurrenLimitMax() != null
                ? config.getChargeCurrenLimitMax() : 29000;
    }

    public Integer getChargingVoltageLimitMax() {
        Config config = getConfig();
        return config != null && config.getChargeVoltageLimitMax() != null
                ? config.getChargeVoltageLimitMax() : 4200;
    }

    public Integer getStopChargingCurrent() {
        Config config = getConfig();
        return config != null && config.getStopCurrent() != null
                ? config.getStopCurrent() : getChargingCurrentLimitMax();
    }

    public Integer getStopChargingVoltage() {
        Config config = getConfig();
        return config != null && config.getStopVoltage() != null
                ? config.getStopVoltage() : getChargingVoltageLimitMax();
    }


}
